package com.zzyl.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDTO;
import com.zzyl.dto.NursingLevelPageDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {
    @Autowired
    private NursingLevelMapper nursingLevelMapper;
    @Override
    public List<NursingLevelVO> selectAll() {

        return nursingLevelMapper.selectAll();
    }

    @Override
    public PageResponse<NursingLevelVO> pageCondition(NursingLevelPageDto nursingLevelPageDto) {
        PageHelper.startPage(nursingLevelPageDto.getPageNum(),nursingLevelPageDto.getPageSize());
        Page<NursingLevelVO> page = nursingLevelMapper.pageCondition(nursingLevelPageDto);
        PageResponse<NursingLevelVO> pageResponse = PageResponse.of(page, NursingLevelVO.class);
        return pageResponse;
    }

    @Override
    public void insert(NursingLevelDTO nursingLevelDTO) {
        NursingLevel nursingLevel = new NursingLevel();
        BeanUtils.copyProperties(nursingLevelDTO,nursingLevel);
        nursingLevelMapper.insert(nursingLevel);
    }

    @Override
    public NursingLevelVO getById(Long id) {
        return nursingLevelMapper.getById(id);
    }

    @Override
    public void update(NursingLevelDTO nursingLevelDTO) {
        NursingLevel nursingLevel = new NursingLevel();
        BeanUtils.copyProperties(nursingLevelDTO,nursingLevel);
        nursingLevelMapper.update(nursingLevel);
    }

    @Override
    public void delete(Long id) {
        NursingLevel nursingLevel = new NursingLevel();
        nursingLevel.setId(id);
        nursingLevel.setIsDelete(1);
        nursingLevelMapper.update(nursingLevel);
    }

    @Override
    public void changeStatus(Long id, Integer status) {
        if(status == 1){
            status = 0;
        }else if (status == 0){
            status = 1;
        }
        NursingLevel nursingLevel = new NursingLevel();
        nursingLevel.setStatus(status);
        nursingLevel.setId(id);
        nursingLevelMapper.update(nursingLevel);
    }
}
